package kernel;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

class Pointer //已打开文件表中读、写指针的结构
{
	private int dnum; // 磁盘盘块号
	private int bnum; // 磁盘盘块内第几个字节

	public Pointer()
	{
		this.bnum=0;
		this.dnum=0;
	}

	public Pointer(int d, int b)
	{
		this.dnum = d;
		this.bnum = b;
	}

	public int getDnum()
	{
		return dnum;
	}

	public void setDnum(int dnum)
	{
		this.dnum = dnum;
	}

	public int getBnum()
	{
		return bnum;
	}

	public void setBnum(int bnum)
	{
		this.bnum = bnum;
	}
}

public class Oftle//已打开文件表的表项定义
{
	private String name; //文件绝对路径名
	private byte attribute; //文件的属性，用 1 个字节表示
	private int number; //文件起始盘块号
	private int length; //文件长度，文件占用的字节数
	private int flag; //操作类型，用“0”表示以读操作方式打开文件，用“1”表示以写操作方式打开文件
	private Pointer read; //读文件的位置，文件打开时 dnum 为文件起始盘块号，bnum 为“0”
	private Pointer write; //写文件的位置，文件刚建立时 dnum 为文件起始盘块号，bnum 为“0 ，打开文件时 dnum 和 bnum 为文件的末尾位置

	//这两个属性是界面的表格的
	private StringProperty nameP = new SimpleStringProperty();
	private StringProperty flagP = new SimpleStringProperty();
	
	public StringProperty getNameP()
	{
		return nameP;
	}
	public void setNameP()
	{
		this.nameP.set(name);
	}
	public StringProperty getFlagP()
	{
		return flagP;
	}
	public void setFlagP()
	{
		this.flagP.set((flag==0)?"读":"写");
	}

	
	public Oftle()
	{
		
	}
	public Oftle(String name, byte attribute, int number, int length, int flag)
	{
		this.name=name;
		this.attribute=attribute;
		this.number=number;
		this.length=length;
		this.flag=flag;
		setNameP();
		setFlagP();
	}

	public void newPointer()
	{
		this.read = new Pointer();
		this.write = new Pointer();
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
		setNameP();
	}

	public byte getAttribute()
	{
		return attribute;
	}

	public void setAttribute(byte attribute)
	{
		this.attribute = attribute;
	}

	public int getNumber()
	{
		return number;
	}

	public void setNumber(int number)
	{
		this.number = number;
	}

	public int getLength()
	{
		return length;
	}

	public void setLength(int length)
	{
		this.length = length;
	}

	public int getFlag()
	{
		return flag;
	}

	public void setFlag(int flag)
	{
		this.flag = flag;
		setFlagP();
	}

	public Pointer getRead()
	{
		return read;
	}

	public void setRead(Pointer read)
	{
		this.read = read;
	}

	public Pointer getWrite()
	{
		return write;
	}

	public void setWrite(Pointer write)
	{
		this.write = write;
	}
}
